package com.mhkjup.artcircle.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class TimeUtil {
	/**
	 * 获取当前时间 yyyy-mm-dd HH:mm:ss
	 * 
	 * @return
	 */
	public static String getCurrentTimeSceond() {
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String time = format.format(new Date());
		return time;
	}

	/**
	 * 设置某个时间点后 例如参数10 意思就是获取十分钟以后的时间 格式 yyyy-mm-dd HH:mm:ss
	 * 
	 * @param minute
	 * @return
	 */
	public static String getAfterTenTimeSceond(int minute) {
		long currentTime = System.currentTimeMillis() + minute * 60 * 1000;
		Date date = new Date(currentTime);
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String nowTime = df.format(date);
		return nowTime;
	}

	public static void main(String[] args) {
		System.out.println(getStrTime("1483200200000"));
	}

	// 时间字符串戳5165165转换成2017-11-29 16:10:41
	public static String getStrTime(String cc_time) {
		Long timeLong = Long.parseLong(cc_time);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = null;
		try {
			date = sdf.parse(sdf.format(timeLong));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} // 你要的日期格式
		return sdf.format(date).toString();
	}

	/**
	 * 获取当前时间 yyyy-mm-dd hh:mm:ss
	 * 
	 * @return
	 */
	public static String getCurrentTimeMinute() {
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String time = format.format(new Date());
		return time;
	}

	public static String getCurrentTimeDay() {
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		String time = format.format(new Date());
		return time;
	}

	public static String convertTimeSceond(Date date) {
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String time = format.format(date);
		return time;
	}

	public static String convertTimeDay(Date date) {
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		String time = format.format(date);
		return time;
	}

	public static String convertTimeDayMonth(Date date) {
		DateFormat format = new SimpleDateFormat("yyyy-MM");
		String time = format.format(date);
		return time;
	}

	public static Date convertDateSceond(String time) {
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = null;
		try {
			date = format.parse(time);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}

	public static Date convertDateDayNew(String time) {
		DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
		Date date = null;
		try {
			date = format.parse(time);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}

	public static Date getCurrentTimeMinute(String time) {
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		Date date = null;
		try {
			date = format.parse(time);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}

	public static Date getNewDate() {
		Date date = new Date();
		return date;
	}

	public static Date convertDateMonth(String time) {
		DateFormat format = new SimpleDateFormat("yyyy-MM");
		Date date = null;
		try {
			date = format.parse(time);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}

	/**
	 * 判断某个时间是否大于当前时间
	 * 
	 * @param date1
	 * @param date2
	 * @return
	 */
	public static boolean compDate(String date1, String date2) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		boolean time = false;
		try {
			Date dates1 = format.parse(date1);
			Date dates2 = format.parse(date2);
			if (dates1.getTime() > dates2.getTime()) {
				time = true;
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return time;
	}

	public static String getuniqukey() {
		DateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
		String time = format.format(new Date());
		return time;
	}

	/**
	 * 随机返回值类型 20170203+6位随机数
	 * 
	 * @return
	 */
	public static String getOrderId() {
		DateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
		String time = format.format(new Date());
		int flag = new Random().nextInt(999999);
		if (flag < 100000) {
			flag += 100000;
		}
		return "yt" + time + flag;
	}
}
